package org.dahuatech.ssh.entity.account;

import java.util.Date;
import java.util.Map;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.dahuatech.ssh.entity.IdEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

/**
 * 权限.
 * 
 * 注释见{@link User}.
 * 
 * @author calvin
 */
@Entity
@Table(name = "ACCT_AUTHORITY")
public class Authority extends IdEntity {

    /**
     * 子菜单
     */
    private Map<Long,Authority> childAuthorities=Maps.newTreeMap();
    /**
     * 编码
     */
    private String code;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 创建用户ID
     */
    private Long createUserId;
    /**
     * 菜单名
     */
    private String name;
    /**
     * 排序
     */
    private Long order;
    
    /**
     * 父菜单id
     */
    private Long pId;
    
    
    /**
     * 对应权限组
     */
    private Set<Role> roles=Sets.newHashSet();
    
    /**
     * url路径
     */
    private String url;
    
    public Authority(){
        
    }
    public Authority(Long id, String name) {
		this.id = id;
		this.name = name;
	}
    @Transient
    public Map<Long,Authority> getChildAuthorities() {
        return childAuthorities;
    }
    @Column(name="menu_code")
    public String getCode() {
        return code;
    }
    @Column
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreateTime() {
        return createTime;
    }
    @Column
    public Long getCreateUserId() {
        return createUserId;
    }
    @Column(name="menu_name")
    public String getName() {
        return name;
    }
    @Column(name="menu_order")
    public Long getOrder() {
        return order;
    }
    @Column(name="pid")
    public Long getpId() {
        return pId;
    }
    @ManyToMany(fetch=FetchType.LAZY,mappedBy="authorities")
	public Set<Role> getRoles() {
		return roles;
	}
    @Column
    public String getUrl() {
        return url;
    }
    public void setChildAuthorities(Map<Long,Authority> childAuthorities) {
        this.childAuthorities = childAuthorities;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public void setCreateUserId(Long createUserId) {
        this.createUserId = createUserId;
    }
    public void setName(String name) {
        this.name = name;
    }
    
	public void setOrder(Long order) {
        this.order = order;
    }
	public void setpId(Long pId) {
        this.pId = pId;
    }
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	public void setUrl(String url) {
        this.url = url;
    }
}
